package com.seteam.collabcrossword.messages.client;

import com.seteam.collabcrossword.CollabCrosswordUtils;
import com.seteam.collabcrossword.Coordinates;
import com.seteam.collabcrossword.Globals;
import com.seteam.collabcrossword.exceptions.CoordinatesException;
import com.seteam.collabcrossword.messages.Message;
import com.seteam.collabcrossword.types.Direction;

import java.io.Serializable;

/**
 * The client uses this message to request a lock from the server. It sends
 * out the starting coordinate of the word, and the direction in which the
 * lock is desired.
 */
public class RequestLock implements Serializable, Message {
    private static final long serialVersionUID = 8999116950320931938L;
    private Direction direction;
    private Coordinates startOfWord;

    /**
     * Constructor
     *
     * @param startOfWord the coordinates of the starting letter of the word
     * @param direction   the direction in which a lock on the word is desired
     * @throws CoordinatesException if the coordinates passed is null
     */
    public RequestLock(final Coordinates startOfWord, final Direction direction)
            throws CoordinatesException {
        CollabCrosswordUtils.checkNotNull(startOfWord, Globals.REQUEST_LOCK_ERROR +
                "startOfWord cannot be null");
        this.startOfWord = startOfWord;
        this.direction = direction;
    }

    /**
     * Getter for startOfWord
     *
     * @return the coordinates of the starting letter of the word
     */
    public Coordinates getStartOfWord() {
        return startOfWord;
    }

    /**
     * Getter for direction
     *
     * @return the direction in which a lock on the word is desired
     */
    public Direction getDirection() {
        return direction;
    }

    /**
     * {@inheritDoc}
     */
    public String getAction() {
        return Globals.REQUEST_LOCK;
    }
}
